﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.MapEditor.Operations
{
	internal class Scale : Operation
	{
        List<TransformItem> Items;
        float Delta;
        bool Snap;

        internal Scale(List<TransformItem> Items, float Delta, bool Snap)
        {
            this.Items = Items;
            this.Delta = Delta;
            this.Snap = Snap;
        }

        internal Scale(Data.Scalable Scalable, float Delta, Object Tag, bool Snap)
        {
            this.Items = new List<TransformItem>();
            this.Items.Add(new TransformItem { Transformee = Scalable, TransformationTag = Tag });
            this.Delta = Delta;
            this.Snap = Snap;
        }

		internal override ReturnCode Do(EditorState ES)
		{
            foreach (var Item in Items)
            {
                var Scalable = Item.Transformee as Data.Scalable;
                if (Scalable != null)
                {
                    Scalable.ApplyScale(Item.TransformationTag, Delta);
                    if (Snap) Scalable.Snap(Snapper.GetSnapper(ES));
                }
            }
			return ReturnCode.AddToUndoStack;
		}

        internal override void Undo(EditorState ES)
        {
            foreach (var Item in Items)
            {
                var Scalable = Item.Transformee as Data.Scalable;
                if (Scalable != null)
                    Scalable.ApplyScale(Item.TransformationTag, 0);

            }
        }
	}
}
